package com.cencat.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.cencat.common.entity.BaseEntity;
import com.cencat.common.enums.GrantType;
import com.cencat.common.enums.DataScope;
import com.cencat.common.enums.DataStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * 用户角色关联实体类
 * 
 * @author cencat
 * @since 2024-01-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "sys_user_role")
public class UserRole extends BaseEntity {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    @Column(name = "id")
    private Long id;

    /**
     * 用户ID
     */
    @Column(name = "user_id", nullable = false)
    private Long userId;

    /**
     * 角色ID
     */
    @Column(name = "role_id", nullable = false)
    private Long roleId;

    /**
     * 授权类型（GRANT-授权，DENY-拒绝）
     */
    @Column(name = "grant_type", nullable = false)
    @Enumerated(EnumType.STRING)
    private GrantType grantType;

    /**
     * 数据权限范围
     */
    @Column(name = "data_scope")
    @Enumerated(EnumType.STRING)
    private DataScope dataScope;

    /**
     * 自定义数据权限SQL条件
     */
    @Column(name = "data_condition", length = 1000)
    private String dataCondition;

    /**
     * 过期时间
     */
    @Column(name = "expire_time")
    private LocalDateTime expireTime;

    /**
     * 状态（ACTIVE-启用，INACTIVE-禁用）
     */
    @Column(name = "status", nullable = false)
    @Enumerated(EnumType.STRING)
    private DataStatus status;

    /**
     * 备注
     */
    @Column(name = "remark", length = 500)
    private String remark;
}